<?php
/**
 * Fetion.php
 *
 * 移动飞信发送表单生成类
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://momoger.com/license
 *
 * @category	Momoger
 * @package 	Momoger_Form
 * @author 		Guya
 * @version    	1.0
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */

/**
 * 移动飞信发送表单生成类.
 *
 * @category	Momoger
 * @package 	Momoger_Form
 * @copyright  	Copyright © 2009 www.momoger.com All Rights Reserved.
 * @license    	http://momoger.com/license     New BSD License
 */
class Momoger_Form_Fetion {

	/**
	 * 创建中国移动飞信发送FORM, 设置4个元素, 发送者，发送者飞信密码, 接收者，短信内容, id: fetion-form
	 * 发送者手机号码 比如： 13838383838 id: sender-input
	 * 发送者飞信密码 比如： 888888 id: passwd-input
	 * 发送者手机号码 比如： 13838383838 id: receiver-input
	 * 短信内容： 两个字符以上. id: sms-input
	 *
	 * @param string $form_action 表单提交地址
	 * @return Zend_Form
	 */
	public function getFetionForm($form_action = null) {

		//the input elements attribute: name, there is need validate
		$inputs = array( 'sender' => 'sender', 'passwd' => 'passwd', 'receiver' => 'receiver', 'sms' => 'sms');

		//create form object
		$form = new Zend_Form();
		$form->setAction($form_action)
			 ->setMethod('post')
			 ->addAttribs(array('id' => 'fetion-form'));

		//create sender phone number input element
		$senderPhone = $form->createElement('text', $inputs['sender'], array('label' => 'Your Mobile Phone number:', 'id' => 'sender-input', 'class' => 'textInput'));

		//add validator and filter for sender phone number input
		$senderPhone->addValidator('regex', FALSE, array('/^[0-9]{11}$/'))->setRequired(TRUE);

		//create senderfetion password input element
		$fetionPasswd = $form->createElement('password', $inputs['passwd'], array('label' => 'Your Fetion account password:', 'id' => 'passwd-input', 'class' => 'textInput'));

		//add some validator
		$fetionPasswd->addValidator('StringLength', FALSE, array(2,20))->setRequired(TRUE);

		//create fetion friend number input element
		$receiverPhone = $form->createElement('text', $inputs['receiver'], array('label' => 'Your Fetion friend phone number:', 'id' => 'receiver-input', 'class' => 'textInput'));

		//add validator and filter for fetion friend number input
		$receiverPhone->addValidator('regex', FALSE, array('/^[0-9]{11}$/'))->setRequired(TRUE);

		//create fetion friend number input element
		$sms = $form->createElement('text', $inputs['sms'], array('label' => 'Fetion message content:', 'id' => 'sms-input', 'class' => 'textInput'));

		//add validator and filter for fetion friend number input
		$sms->addValidator('StringLength', FALSE, array(2,1000))->setRequired(TRUE);

		$submit = $form->createElement('submit', 'submit', array('label' => 'Send SMS', 'id' => 'fetion-submit'));
		$form->addElement($senderPhone)
			 ->addElement($fetionPasswd)
			 ->addElement($receiverPhone)
			 ->addElement($sms)
			 ->addElement($submit);
		return $form;
	}

	/**
	 * 获取自定义错误信息, 登录信息失败可以获取相关的失败信息.
	 *
	 * @param array $errors Zend_Form 错误提示信息
	 * @return array
	 */
	public function getErrorMsgs(array $errors) {

		/** Momoger_Form_Message */
		//require_once 'Message.php';

		$labels = array(
			'sender' => 'Your phone number invalid: ',
			'passwd' => 'Your Fetion password invalid: ',
			'receiver' => 'Receiver phone number invalid: ',
			'sms' => 'Message content invalid: '
		);

		return Momoger_Form_Message::getExceptionMsgs($errors, $labels);
	}
}